package com.lej.push.notification

import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.app.PendingIntent.FLAG_CANCEL_CURRENT
import android.content.Context
import android.content.Intent
import android.os.Build
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat.getSystemService
import com.lej.core.base.app
import com.lej.push.R


object NotificationUtils {
    var CHANNEL_ID_MSG = "0"
//    var CHANNEL_ID_NORMAL = "1";
//    var CHANNEL_ID_MARKET = "2";

    /**
     * 发送通知（支持8.0+）
     * @param view
     */
    fun notify(message: String, reqCode: Int, intent: Intent?) {
        val builder: NotificationCompat.Builder = NotificationCompat.Builder(app, CHANNEL_ID_MSG)
            .setSmallIcon(R.drawable.push_small)
            .setContentTitle("Peng消息") // 这是单行
            .setStyle(
                NotificationCompat.BigTextStyle()
                    .bigText(message)
            )
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setAutoCancel(true)

        intent?.let {
            val pendingIntent: PendingIntent = PendingIntent.getActivity(app, 0, it, FLAG_CANCEL_CURRENT)
            builder.setContentIntent(pendingIntent)
        }
        val notificationManager: NotificationManagerCompat = NotificationManagerCompat.from(app)
        notificationManager.notify(System.currentTimeMillis().toInt(), builder.build())
    }

    fun createNotificationChannel(context: Context) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            val notificationManager: NotificationManager = getSystemService(context, NotificationManager::class.java)!!
            ///消息渠道，聊天消息，服务通知等
            val channelMsg = NotificationChannel(CHANNEL_ID_MSG, "乐见club消息推送", NotificationManager.IMPORTANCE_HIGH)
            channelMsg.description = "聊天消息等推送信息展示"
            notificationManager.createNotificationChannel(channelMsg)
//
//            ///普通活动消息，提醒消息等， 一般重要
//            val channelNormal = NotificationChannel(CHANNEL_ID_NORMAL, "peng通知推送", NotificationManager.IMPORTANCE_DEFAULT)
//            channelNormal.description = "活动等通知消息推送"
//            notificationManager.createNotificationChannel(channelNormal)
//
//            ///营销推广消息，提醒消息等，不是很重要
//            val channelMarketing = NotificationChannel(CHANNEL_ID_MARKET, "peng营销推送", NotificationManager.IMPORTANCE_LOW)
//            channelMarketing.description = "推广营销等消息推送"
//            notificationManager.createNotificationChannel(channelMarketing)
        }
    }
}